package com.cms.web.notice;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.cms.biz.business.CMSGeneralContractServiceMgr;
import com.cms.biz.common.EMPContractUtil;
import com.cms.biz.dict.CMSContractServiceMgr;
import com.cms.persistence.noticeMessage.TZGGZD;
import com.dal.common.sequence.UUIDGenerator;
import com.metadata.biz.MetaDataServiceMgr;
import com.persistence.qxgl.beans.SYSUser;
import com.pub.util.ESPKeyValueUtil;
import com.web.BaseController;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.builder.util.EMPRowSetUtil;
import com.efounder.dict.DMTServiceMgr;
import com.efounder.dict.FCTServiceMgr;
import com.efounder.eai.data.JParamObject;
import com.efounder.eai.data.JResponseObject;
import com.efounder.form.server.provider.FormModelDataProvider;
import com.efounder.form.server.resolver.util.FormModelDataResolverUtil;

/** 
 * 消息通知控制器
 * 
 * @author ES
 * @version 1.0
 */
@Controller
@RequestMapping(value="/noticeMessageManager")
public class NoticeMessageController extends BaseController{
	@Autowired
	private                            DMTServiceMgr                        DMTService;
	
	@Autowired
	private                            FCTServiceMgr                        FCTService;
	
	@Autowired
	private                    CMSContractServiceMgr             CMSContractServiceMgr;

	@Autowired
	private                    FormModelDataProvider                     formModelUtil;
	
	@Autowired
	private                FormModelDataResolverUtil                 formModelResolver;
	
	@Autowired
	private             CMSGeneralContractServiceMgr                generalContractMgr;
	
	@Autowired
	private                       MetaDataServiceMgr                metaDataServiceMgr;
	
	@Autowired
	public                               HttpSession                           session;
	
	@Autowired
	public                           EMPContractUtil                      contractUtil;
	
	/**
	 * 公告通知列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/list")
	public String noticeList(@RequestParam String APP_IDS, @RequestParam String APP_ID, Model model) {	
		JParamObject                PO = JParamObject.Create();
		SYSUser                   user = (SYSUser) session.getAttribute("contextUser");
		EFRowSet                rowset = null;
		String                COL_VIEW = "";
		String             strSqlWhere = "";
		String[]           APP_IDArray = null;
		List                  extArray = null;
		EFDataSet               jjcdDS = EFDataSet.getInstance();
		EFDataSet                appDS = EFDataSet.getInstance();
		EFDataSet   itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("TZGGZD");
		
		itemObjColsDataSet.setPrimeKey(new String[]{"COL_ID"});
		itemObjColsDataSet.buildPrimeKeyIndex();
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("F_JJCD");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			jjcdDS.addRowSet(r);
		}
		
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("APP_ID");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			if(APP_IDS.contains(array[0])) {
				appDS.addRowSet(r);
			}			
		}
		
		APP_IDArray = APP_IDS.split(";");
		
		for(int i = 0; i < APP_IDArray.length; i++) {
			strSqlWhere += " APP_ID = '" + APP_IDArray[i] + "' or ";
		}
		strSqlWhere = strSqlWhere.substring(0, strSqlWhere.lastIndexOf("or"));
		strSqlWhere = " F_BZDW = '" + user.getUSER_ORGID() + "' and (" + strSqlWhere + ")";
		
		PO.SetValueByParamName("tableName", "TZGGZD");
		PO.SetValueByParamName("BILL_WHERE", strSqlWhere);
		PO.SetValueByParamName("BILL_ORDER", "F_JJCD DESC,F_CRDATE");
		EFDataSet dataset = FCTService.getFCTRows(PO);
		model.addAttribute("dataset", dataset);
		model.addAttribute("user", user);
		model.addAttribute("APP_IDS", APP_IDS);
//		model.addAttribute("APP_ID", APP_ID);
		model.addAttribute("jjcdDS", jjcdDS);
		model.addAttribute("appDS", appDS);
		
		return "/cms/noticeMessage/list";
	}
	
	/**
	 * 公告通知添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/add")
	public String noticeMessageAdd(@RequestParam String APP_IDS, @RequestParam String APP_ID, Model model) {	
		//新建通知公告
		String                  F_GUID = UUIDGenerator.nextId();
		SYSUser                   user = (SYSUser) session.getAttribute("contextUser");
		TZGGZD                    ggzd = new TZGGZD();
		EFRowSet                rowset = null;
		String                COL_VIEW = "";
		List                  extArray = null;
		EFDataSet               jjcdDS = EFDataSet.getInstance();
		EFDataSet                appDS = EFDataSet.getInstance();
		EFDataSet   itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("TZGGZD");
		itemObjColsDataSet.setPrimeKey(new String[]{"COL_ID"});
		itemObjColsDataSet.buildPrimeKeyIndex();
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("F_JJCD");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			jjcdDS.addRowSet(r);
		}
		
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("APP_ID");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			if(APP_IDS.contains(array[0])) {
				appDS.addRowSet(r);
			}			
		}
		
		ggzd.setF_GUID(F_GUID);
		ggzd.setF_BZR(user.getUSER_ID());
		ggzd.setF_BZRMC(user.getUSER_NAME());
		ggzd.setF_BZDW(user.getUSER_ORGID());
		ggzd.setF_GGZT("0");
		model.addAttribute("dictObject", ggzd);
		model.addAttribute("FORM_TYPE", "0");
		model.addAttribute("user", user);
		model.addAttribute("APP_IDS", APP_IDS);
		model.addAttribute("APP_ID", APP_ID);
		model.addAttribute("jjcdDS", jjcdDS);
		model.addAttribute("appDS", appDS);
		return "/cms/noticeMessage/form";
	}
	
	/**
	 * 合同信息编辑
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/noticeMessage/edit/{F_GUID}")
	public String noticeMessageEdit(@PathVariable("F_GUID") String F_GUID, @RequestParam String APP_IDS, @RequestParam String F_JJCD, @RequestParam String APP_ID, Model model) throws Exception {	
		EFRowSet               rowset = null;
		SYSUser                  user = (SYSUser) session.getAttribute("contextUser");
		TZGGZD                   ggzd = new TZGGZD();
		String                COL_VIEW = "";
		List                  extArray = null;
		EFDataSet               jjcdDS = EFDataSet.getInstance();
		EFDataSet                appDS = EFDataSet.getInstance();
		EFDataSet   itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("TZGGZD");
		itemObjColsDataSet.setPrimeKey(new String[]{"COL_ID"});
		itemObjColsDataSet.buildPrimeKeyIndex();
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("F_JJCD");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			jjcdDS.addRowSet(r);
		}
		
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("APP_ID");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			if(APP_IDS.contains(array[0])) {
				appDS.addRowSet(r);
			}			
		}
		
		rowset = DMTService.getRow("TZGGZD", "F_GUID", F_GUID);
		ggzd.setF_GUID(rowset.getString("F_GUID", ""));
		ggzd.setF_BZDW(rowset.getString("F_BZDW", ""));
		ggzd.setF_BZR(rowset.getString("F_BZR", ""));
		ggzd.setF_BZDWMC(rowset.getString("USER_NAME", ""));
		ggzd.setF_GGBT(rowset.getString("F_GGBT", ""));
		ggzd.setF_GGNR(rowset.getString("F_GGNR", ""));
		ggzd.setF_GGZT(rowset.getString("F_GGZT", ""));
		ggzd.setF_CRDATE(rowset.getDate("F_CRDATE", null));
		ggzd.setF_FBRQ(rowset.getDate("F_FBRQ", null));
		model.addAttribute("dictObject", ggzd);
		model.addAttribute("FORM_TYPE", "1");
		model.addAttribute("user", user);
		model.addAttribute("APP_IDS", APP_IDS);
		model.addAttribute("F_JJCD", F_JJCD);
		model.addAttribute("APP_ID", APP_ID);
		model.addAttribute("jjcdDS", jjcdDS);
		model.addAttribute("appDS", appDS);
		return "/cms/noticeMessage/form";
	}
	
	/**
	 * 合同信息编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/update")
	public ModelAndView noticeMessageUpdate(@RequestParam String FORM_TYPE, @RequestParam String APP_IDS, TZGGZD tzggzd, Model model) {
		EFRowSet               rowset = null;
		SYSUser                  user = (SYSUser) session.getAttribute("contextUser");
		JParamObject               PO = JParamObject.Create();
		
		if(FORM_TYPE.equals("0")) {
			try {
				rowset = EMPRowSetUtil.createRowSet(tzggzd);
				rowset.putString("F_BZR", user.getUSER_ID());
				rowset.putString("F_BZDW", user.getUSER_ORGID());
				rowset.putDate("F_CRDATE", new Date());
				rowset.putDate("F_CHDATE", new Date());
				PO.SetValueByParamName("DCI_ID", "HTXMZD");
				
				JResponseObject RO = FCTService.insertFCTRow("TZGGZD", rowset);
				if(RO.getErrorCode() == -1) {
					return ajaxDoneError(RO.getErrorString());
				} else {
					ModelAndView modelView = ajaxDoneSuccess(RO.ResponseObject.toString());
					MappingJacksonJsonView view = (MappingJacksonJsonView)modelView.getView();
					Map attributes = view.getAttributesMap();
					String forwardUrl = attributes.get("forwardUrl").toString();
					forwardUrl += "?APP_IDS=" + APP_IDS + "&APP_ID=" + tzggzd.getAPP_ID() + "&F_JJCD=" + tzggzd.getF_JJCD();
					attributes.put("forwardUrl", forwardUrl);
					return modelView; 
				}
			} catch (Exception e) {
				e.printStackTrace();
				return ajaxDoneError(e.getMessage());
			}
		}
		
		else {
			rowset = DMTService.getRow("TZGGZD", "F_GUID", tzggzd.getF_GUID());
			rowset.putString("APP_ID", tzggzd.getAPP_ID());
			rowset.putString("F_GGBT", tzggzd.getF_GGBT());
			rowset.putString("F_GGNR", tzggzd.getF_GGNR());
			rowset.putString("F_JJCD", tzggzd.getF_JJCD());
			rowset.putString("F_BZR", user.getUSER_ID());
			rowset.putString("F_BZDW", user.getUSER_ORGID());
			rowset.putString("F_BZR", user.getUSER_ID());
			rowset.putString("F_BZDW", user.getUSER_ORGID());
			rowset.putDate("F_CHDATE", new Date());
			JResponseObject RO = DMTService.updateRow("TZGGZD", rowset);
			if(RO.getErrorCode() == -1) {
				return ajaxDoneError(RO.getErrorString());
			} else {
				ModelAndView modelView = ajaxDoneSuccess(RO.ResponseObject.toString());
				MappingJacksonJsonView view = (MappingJacksonJsonView)modelView.getView();
				Map attributes = view.getAttributesMap();
				String forwardUrl = attributes.get("forwardUrl").toString();
				forwardUrl += "?APP_IDS=" + APP_IDS + "&APP_ID=" + tzggzd.getAPP_ID() + "&F_JJCD=" + tzggzd.getF_JJCD();
				attributes.put("forwardUrl", forwardUrl);
				return modelView; 
			}
		}
	}
	
	/**
	 * 合同信息删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/delete/{F_GUID}")
	public ModelAndView generalContractDelete(@PathVariable("F_GUID") String F_GUID) {	
		JResponseObject RO = DMTService.deleteRow("TZGGZD", F_GUID);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 公告通知发布
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/submit/{F_GUID}")
	public ModelAndView noticeMessageSubmit(@PathVariable("F_GUID") String F_GUID, @RequestParam String APP_IDS, Model model) {	
		//新建通知公告
		EFRowSet               rowset = null;

		rowset = DMTService.getRow("TZGGZD", "F_GUID", F_GUID);
		rowset.putString("F_GGZT", "1");
		rowset.putDate("F_CHDATE", new Date());
		rowset.putDate("F_FBRQ", new Date());
		JResponseObject RO = DMTService.updateRow("TZGGZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			ModelAndView modelView = ajaxDoneSuccess(RO.ResponseObject.toString());
			MappingJacksonJsonView view = (MappingJacksonJsonView)modelView.getView();
			Map attributes = view.getAttributesMap();
			String forwardUrl = attributes.get("forwardUrl").toString();
			forwardUrl += "?APP_IDS=" + APP_IDS + "&APP_ID=" + rowset.getString("APP_ID", "") + "&F_JJCD=" + rowset.getString("F_JJCD", "");
			attributes.put("forwardUrl", forwardUrl);
			return modelView; 
		}
	}
	
	/**
	 * 公告通知取消发布
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/cancelSubmit/{F_GUID}")
	public ModelAndView noticeMessageCancelSubmit(@PathVariable("F_GUID") String F_GUID, @RequestParam String APP_IDS, Model model) {	
		//新建通知公告
		EFRowSet               rowset = null;

		rowset = DMTService.getRow("TZGGZD", "F_GUID", F_GUID);
		rowset.putString("F_GGZT", "0");
		rowset.putDate("F_CHDATE", new Date());
		rowset.putDate("F_FBRQ", new Date());
		JResponseObject RO = DMTService.updateRow("TZGGZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			ModelAndView modelView = ajaxDoneSuccess(RO.ResponseObject.toString());
			MappingJacksonJsonView view = (MappingJacksonJsonView)modelView.getView();
			Map attributes = view.getAttributesMap();
			String forwardUrl = attributes.get("forwardUrl").toString();
			forwardUrl += "?APP_IDS=" + APP_IDS + "&APP_ID=" + rowset.getString("APP_ID", "") + "&F_JJCD=" + rowset.getString("F_JJCD", "");
			attributes.put("forwardUrl", forwardUrl);
			return modelView; 
		}
	}
	
	/**
	 * 公告通知列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/queryList")
	public String noticeQueryList(@RequestParam String APP_IDS, @RequestParam String APP_ID, Model model) {	
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		EFRowSet                rowset = null;
		String                COL_VIEW = "";
		String             strSqlWhere = "";
		String[]           APP_IDArray = null;
		List                  extArray = null;
		EFDataSet               jjcdDS = EFDataSet.getInstance();
		EFDataSet                appDS = EFDataSet.getInstance();
		EFDataSet   itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("TZGGZD");
		
		itemObjColsDataSet.setPrimeKey(new String[]{"COL_ID"});
		itemObjColsDataSet.buildPrimeKeyIndex();
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("F_JJCD");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			jjcdDS.addRowSet(r);
		}
		
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("APP_ID");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			if(APP_IDS.contains(array[0])) {
				appDS.addRowSet(r);
			}			
		}
		
		APP_IDArray = APP_IDS.split(";");
		
		for(int i = 0; i < APP_IDArray.length; i++) {
			strSqlWhere += " APP_ID = '" + APP_IDArray[i] + "' or ";
		}
		strSqlWhere = strSqlWhere.substring(0, strSqlWhere.lastIndexOf("or"));
		strSqlWhere = " F_BZDW = '" + user.getUSER_ORGID() + "' and (" + strSqlWhere + ")";
		
		PO.SetValueByParamName("tableName", "TZGGZD");
		PO.SetValueByParamName("BILL_WHERE", strSqlWhere);
		PO.SetValueByParamName("BILL_ORDER", "F_JJCD DESC,F_CRDATE");
		EFDataSet dataset = FCTService.getFCTRows(PO);
		model.addAttribute("dataset", dataset);
		model.addAttribute("user", user);
		model.addAttribute("APP_IDS", APP_IDS);
//		model.addAttribute("APP_ID", APP_ID);
		model.addAttribute("jjcdDS", jjcdDS);
		model.addAttribute("appDS", appDS);
		
		return "/cms/noticeMessage/queryList";
	}
	
	
	/**
	 * 合同信息编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/showNoticeMessage")
	public String showNoticeMessage(@RequestParam String F_GUID, Model model) {
		EFRowSet               rowset = null;
		SYSUser                  user = (SYSUser) session.getAttribute("contextUser");
		TZGGZD                   ggzd = new TZGGZD();
		
		rowset = DMTService.getRow("TZGGZD", "F_GUID", F_GUID);
		ggzd.setF_GUID(rowset.getString("F_GUID", ""));
		ggzd.setF_BZDW(rowset.getString("F_BZDW", ""));
		ggzd.setF_BZR(rowset.getString("F_BZR", ""));
		ggzd.setF_BZRMC(rowset.getString("USER_NAME", ""));
		ggzd.setF_BZDWMC(rowset.getString("USER_NAME", ""));
		ggzd.setF_GGBT(rowset.getString("F_GGBT", ""));
		ggzd.setF_GGNR(rowset.getString("F_GGNR", ""));
		ggzd.setF_GGZT(rowset.getString("F_GGZT", ""));
		ggzd.setF_CRDATE(rowset.getDate("F_CRDATE", null));
		ggzd.setF_FBRQ(rowset.getDate("F_FBRQ", null));
		model.addAttribute("dictObject", ggzd);
		model.addAttribute("FORM_TYPE", "1");
		model.addAttribute("user", user);
		return "/cms/noticeMessage/showForm";
	}
	
	/**
	 * 公告通知查找
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/add/search")
	public String addNoticeList(@RequestParam String F_GGBT, @RequestParam String APP_IDS, @RequestParam String APP_ID, @RequestParam String F_JJCD, @RequestParam String F_FBZT, Model model) {	
		JParamObject                PO = JParamObject.Create();
		SYSUser                   user = (SYSUser) session.getAttribute("contextUser");
		String                sqlWhere = "";
		EFRowSet                rowset = null;
		String                COL_VIEW = "";
		String             strSqlWhere = "";
		String[]           APP_IDArray = null;
		List                  extArray = null;
		EFDataSet               jjcdDS = EFDataSet.getInstance();
		EFDataSet                appDS = EFDataSet.getInstance();
		EFDataSet   itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("TZGGZD");
		
		itemObjColsDataSet.setPrimeKey(new String[]{"COL_ID"});
		itemObjColsDataSet.buildPrimeKeyIndex();
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("F_JJCD");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			jjcdDS.addRowSet(r);
		}
		
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("APP_ID");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			if(APP_IDS.contains(array[0])) {
				appDS.addRowSet(r);
			}			
		}
		
		sqlWhere = " F_GGBT like '%" + F_GGBT + "%' and F_BZR = '" + user.getUSER_ID() 
				 + "' and F_BZDW like '%" + user.getUSER_ORGID() + "%' and F_JJCD like '%" + F_JJCD + "%'";
		
		if(APP_ID.equals("")) {
			APP_IDArray = APP_IDS.split(";");
			
			for(int i = 0; i < APP_IDArray.length; i++) {
				strSqlWhere += " APP_ID = '" + APP_IDArray[i] + "' or ";
			}
			sqlWhere += " and (" + strSqlWhere.substring(0, strSqlWhere.lastIndexOf("or")) + ")";
		} else {
			sqlWhere += " and APP_ID like '%" + APP_ID + "%'";
		}
		

		if(F_FBZT.equals("0")) {
			sqlWhere += " and F_GGZT = '0'";
		} else if(F_FBZT.equals("1")) {
			sqlWhere += " and F_GGZT = '1'";
		}
		
		PO.SetValueByParamName("tableName", "TZGGZD");
		PO.SetValueByParamName("BILL_WHERE", sqlWhere);
		PO.SetValueByParamName("BILL_ORDER", "F_JJCD DESC,F_CRDATE");
		EFDataSet dataset = FCTService.getFCTRows(PO);
		model.addAttribute("dataset", dataset);
		model.addAttribute("user", user);
		model.addAttribute("F_GGBT", F_GGBT);
		model.addAttribute("F_FBZT", F_FBZT);
		model.addAttribute("APP_IDS", APP_IDS);
		model.addAttribute("APP_ID", APP_ID);
		model.addAttribute("jjcdDS", jjcdDS);
		model.addAttribute("appDS", appDS);
		model.addAttribute("F_JJCD", F_JJCD);
		
		return "/cms/noticeMessage/list";
	}
	
	/**
	 * 公告通知查找
	 * @param model
	 * @return
	 */
	@RequestMapping("/noticeMessage/query/search")
	public String queryNoticeList(@RequestParam String F_GGBT, @RequestParam String APP_IDS, @RequestParam String APP_ID, @RequestParam String F_JJCD, @RequestParam String F_FBZT, Model model) {
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String           sqlWhere = "";
		EFRowSet                rowset = null;
		String                COL_VIEW = "";
		String             strSqlWhere = "";
		String[]           APP_IDArray = null;
		List                  extArray = null;
		EFDataSet               jjcdDS = EFDataSet.getInstance();
		EFDataSet                appDS = EFDataSet.getInstance();
		EFDataSet   itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("TZGGZD");
		
		itemObjColsDataSet.setPrimeKey(new String[]{"COL_ID"});
		itemObjColsDataSet.buildPrimeKeyIndex();
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("F_JJCD");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			jjcdDS.addRowSet(r);
		}
		
		
		rowset = (EFRowSet) itemObjColsDataSet.getRowSet("APP_ID");
		COL_VIEW = rowset.getString("COL_VIEW", "");
		extArray = ESPKeyValueUtil.getKeyValueArray(":", ";", COL_VIEW);
		for(int i = 0; i < extArray.size(); i++) {
			EFRowSet r = EFRowSet.getInstance();
			String[] array = (String[]) extArray.get(i);
			r.putString("KEY", array[0]);
			r.putString("VALUE", array[1]);
			if(APP_IDS.contains(array[0])) {
				appDS.addRowSet(r);
			}			
		}
		
		sqlWhere = " F_GGBT like '%" + F_GGBT + "%' and F_BZR = '" + user.getUSER_ID() 
				 + "' and F_BZDW like '%" + user.getUSER_ORGID() + "%' and F_JJCD like '%" + F_JJCD + "%'";
		
		if(APP_ID.equals("")) {
			APP_IDArray = APP_IDS.split(";");
			
			for(int i = 0; i < APP_IDArray.length; i++) {
				strSqlWhere += " APP_ID = '" + APP_IDArray[i] + "' or ";
			}
			sqlWhere += " and (" + strSqlWhere.substring(0, strSqlWhere.lastIndexOf("or")) + ")";
		} else {
			sqlWhere += " and APP_ID like '%" + APP_ID + "%'";
		}
		

		if(F_FBZT.equals("0")) {
			sqlWhere += " and F_GGZT = '0'";
		} else if(F_FBZT.equals("1")) {
			sqlWhere += " and F_GGZT = '1'";
		}
		
		PO.SetValueByParamName("tableName", "TZGGZD");
		PO.SetValueByParamName("BILL_WHERE", sqlWhere);
		PO.SetValueByParamName("BILL_ORDER", "F_JJCD DESC,F_CRDATE");
		EFDataSet dataset = FCTService.getFCTRows(PO);
		model.addAttribute("dataset", dataset);
		model.addAttribute("user", user);
		model.addAttribute("F_GGBT", F_GGBT);
		model.addAttribute("F_FBZT", F_FBZT);
		model.addAttribute("APP_IDS", APP_IDS);
		model.addAttribute("APP_ID", APP_ID);
		model.addAttribute("jjcdDS", jjcdDS);
		model.addAttribute("appDS", appDS);
		model.addAttribute("F_JJCD", F_JJCD);
		return "/cms/noticeMessage/queryList";
	}
}
